package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.OrderFood;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author pang
 */
@Repository
public interface IOrderFoodMapper {

    /**
     * 根据就餐id查询
     * @param id
     * @return
     */
    @Select("SELECT * FROM e_consfood WHERE id = #{id}")
    @Results(value = {
            @Result(column = "foodId",property = "foods",one = @One(select = "com.xuetang9.t9.hotel.mapper.EFoodMapper.selectByIdConsfood",fetchType = FetchType.EAGER))
    })
    List<OrderFood> selectById(@Param("id")Integer id);


    /**
     * 新增
     * @param orderFood
     * @return
     */
    @Insert("INSERT INTO e_consfood VALUES(#{id},#{foodId},#{count})")
    int insert(OrderFood orderFood);


    /**
     * 更新数量
     * @param orderFood
     * @return
     */
    @Update("UPDATE e_consfood SET count = #{count} WHERE id = #{id} AND foodId = #{foodId}")
    int update(OrderFood orderFood);


    /**
     * 根据事物id和就餐id查询数量
     * @param id
     * @param footId
     * @return
     */
    @Select("SELECT count FROM e_consfood WHERE id=#{id} AND foodId = #{foodId}")
    int selectByIdAndFoodId(@Param("id") Integer id,@Param("footId") Integer footId);

    /**
     * 根据就餐和事物id删除
     * @param id
     * @return
     */
    @Delete("DELETE FROM e_consfood WHERE id=#{id} AND foodId = #{footId}")
    int delete(@Param("id") Integer id,@Param("footId") Integer footId);
}
